from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, Table, VARCHAR, TIMESTAMP, TEXT, text
from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy.orm import relationship
from app.models.base import Base, TimestampMixin, BaseEnum, DictData
from app.models.base import TimestampMixin, Base


class FuncallLogType(BaseEnum):
    TOOL = DictData('tool', '工具')
    AGENT = DictData('agent', '智能体')
class OpenaiLog(Base, TimestampMixin):
    __tablename__ = "openai_log"

    id = Column(Integer, primary_key=True, index=True)
    request_body = Column(LONGTEXT, nullable=False)
    response_body = Column(LONGTEXT,default='', nullable=True)
    url = Column(String(360),default= '',server_default=text("''"),nullable=False)
    chat_id = Column(Integer, nullable=True)

class FuncallLog(Base, TimestampMixin):
    __tablename__ = 'funcall_log'

    __table_args__ = {'comment': '接口funcall调用日志'}
    id = Column(Integer, primary_key=True, comment='主键', autoincrement=True)
    description = Column(VARCHAR(512), nullable=True, comment='描述', server_default=text("''"))
    req_args = Column(TEXT, nullable=True, comment='请求参数')
    #TEXT(16777216) 相当于 mediumtext
    log_text = Column(TEXT(16777216), nullable=True, comment='日志信息')
    remark = Column(VARCHAR(512), nullable=False, comment='备注', server_default=text("''"))
    type = Column(VARCHAR(16), nullable=False, comment='类型', server_default=text("'tool'"))
    status = Column(VARCHAR(8), nullable=False, comment='状态[0:正常,1:错误,2:执行]', server_default=text("'0'"))
    completion_tokens = Column(Integer, nullable=False, comment='完成令牌', server_default=text("'0'"))
    prompt_tokens = Column(Integer, nullable=False, comment='提示令牌', server_default=text("'0'"))
    total_tokens = Column(Integer, nullable=False, comment='总令牌', server_default=text("'0'"))
